package com.luxx.model;

import java.util.HashMap;
import java.util.Map;

import com.luxx.util.DBUtil;

public class CodeGenerator extends AbstractEngine {

	private static final String BASE_PATH = System.getProperty("user.dir");

	private static final String TEMPLATE_PATH = BASE_PATH + "/src/com/luxx/ftl";

	public CodeGenerator() throws Exception {
		super(TEMPLATE_PATH);
	}

	public CodeGenerator(String templatePath) throws Exception {
		super(templatePath);
	}

	public void generateModel(String table) {
		try {
			Map params = new HashMap();
			params.put("table", table);
			params.put("columnList", DBUtil.getTableColumns(con, null, null, table));
			create("entity.ftl", params, BASE_PATH + "/template/model", table.substring(0, 1).toUpperCase()
					+ table.toLowerCase().replaceAll("_", "").substring(1) + ".java");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
